package project.ia04.agents.studio.StaffAgentCommunication;

import java.util.HashMap;

import project.ia04.agents.studio.StudioAgent;
import project.ia04.agents.studio.GUICommunication.StepXSequentialBehaviour;
import project.ia04.utils.Data;
import jade.core.behaviours.OneShotBehaviour;
import jade.lang.acl.ACLMessage;
import jade.lang.acl.MessageTemplate;

public class UpdateItemsBehaviour extends OneShotBehaviour {
	
	private ACLMessage message;
	
	public UpdateItemsBehaviour(ACLMessage message){
		this.message = message;
	}

	@Override
	public void action() {
			// UPDATE MODEL
			final HashMap<String, Integer> map = ((StudioAgent)myAgent).deserializeItems(message
					.getContent());
			((StudioAgent)myAgent).getCurrentGame()
					.setLvlCreativity(((StudioAgent)myAgent).getCurrentGame()
							.getLvlCreativity()
							+ map.get(Data.CREATIVITYITEM));
			((StudioAgent)myAgent).getCurrentGame()
					.setLvlGameplay(((StudioAgent)myAgent).getCurrentGame()
							.getLvlGameplay()
							+ map.get(Data.GAMEPLAYITEM));
			((StudioAgent)myAgent).getCurrentGame()
					.setLvlGraphism(((StudioAgent)myAgent).getCurrentGame()
							.getLvlGraphism()
							+ map.get(Data.GRAPHISMITEM));
			((StudioAgent)myAgent).getCurrentGame()
					.setLvlSound(((StudioAgent)myAgent).getCurrentGame()
							.getLvlSound()
							+ map.get(Data.SOUNDITEM));

			// SEND 2 VIEW
			ACLMessage reply = new ACLMessage(ACLMessage.INFORM);
			System.out.println("Update Progress StudioAgent");
			reply = new ACLMessage(ACLMessage.INFORM);
			reply.setConversationId(Data.UPDATEPROGRESS);
			reply.setContent(((StudioAgent)myAgent).serializeItems(
					((StudioAgent)myAgent).getCurrentGame()
							.getLvlGameplay(),
							((StudioAgent)myAgent).getCurrentGame()
							.getLvlGraphism(),
							((StudioAgent)myAgent).getCurrentGame().getLvlSound(),
							((StudioAgent)myAgent).getCurrentGame()
							.getLvlCreativity()));
			reply.addReceiver(((StudioAgent)myAgent).getXAgent());
			this.myAgent.send(reply);
	}

}
